package largestNumberFromDigits;

import java.util.*;

public class LargestNumberFromDigits {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter a very large number:");
        String input = scanner.nextLine();
        char[] digits = input.toCharArray();

        HashMap<Character,Integer>hm=new HashMap<>();
        for(char ch:digits){
            hm.put(ch,hm.getOrDefault(ch,0)+1);
        }

        Iterator<HashMap.Entry<Character,Integer>>it=hm.entrySet().iterator();
        int[] count=new int[10];
        Arrays.fill(count,0);

        Map.Entry<Character,Integer>entryTemp;
        while(it.hasNext()){
            entryTemp=it.next();
            count[(entryTemp.getKey()-'0')]=entryTemp.getValue();
        }

        StringBuilder largestNumber = new StringBuilder();
        for(int i=9;i>=0;i--){
            while(count[i]!=0){
                count[i]--;
                largestNumber.append(i);
            }
        }

        System.out.println("The largest number is: " + largestNumber);
        scanner.close();
    }
}
